"""
ChatBot configurations and constants
"""
from chatbot.component.singleton import singleton


@singleton
class Conf(object):
    """
    Scripts for fixed scenario
    """

    # 欢迎语
    SCRIPT_GREETING = 'SCRIPT_BOT_GREETING'
    SCRIPT_GREETING_DEFAULT = '你好，欢迎使用智能机器人哦，我是小智，有问题尽管问我吧！'
    # 欢迎语推荐问题前置语
    SCRIPT_GREETING_QUESTION_RECOMMEND_GUIDING = 'SCRIPT_GREETING_QUESTION_RECOMMEND_GUIDING'
    SCRIPT_GREETING_QUESTION_RECOMMEND_GUIDING_DEFAULT = '猜你想问：'
    # 欢迎语推荐问题
    SCRIPT_GREETING_RECOMMEND_QUESTION = 'SCRIPT_GREETING_QUESTION_RECOMMEND'

    # 未知回复
    SCRIPT_UNKNOWN_REPLY = 'SCRIPT_UNKNOWN_REPLY'
    SCRIPT_UNKNOWN_REPLY_DEFAULT = '哎呀，这个太难了，我还没有学习过，能换一个问题吗？'
    # 敏感词触发提示语
    SCRIPT_SENSITIVE_WORD = 'SCRIPT_SENSITIVE_WORD'
    SCRIPT_SENSITIVE_WORD_DEFAULT = '您的话中含有敏感信息，请注意用词哈'
    # 反问引导前置语
    SCRIPT_CLARIFY_WORD = 'SCRIPT_CLARIFY_WORD'
    SCRIPT_CLARIFY_WORD_DEFAULT = '你是想问以下哪一个问题：'

    # 答案满意度点赞话术
    SCRIPT_ANSWER_LIKED = 'SCRIPT_ANSWER_LIKED'
    SCRIPT_ANSWER_LIKED_DEFAULT = '谢谢你的鼓励，我会加倍努力更好的回答问题哦'
    # 答案满意度点踩话术
    SCRIPT_ANSWER_DISLIKED = 'SCRIPT_ANSWER_DISLIKED'
    SCRIPT_ANSWER_DISLIKED_DEFAULT = '呜呜，没能解决您的问题，我很伤心，呜呜'
    # 答案满意度不满意原因收集邀请话术
    SCRIPT_ANSWER_DISLIKE_REASON_COLLECT_INVITE = 'SCRIPT_ANSWER_DISLIKE_REASON_COLLECT_INVITE'
    SCRIPT_ANSWER_DISLIKE_REASON_COLLECT_INVITE_DEFAULT = '请指出我错在哪里了哦，以便我能及时改正哈'
    # 答案满意度不满意原因
    SCRIPT_ANSWER_DISLIKE_REASONS = 'SCRIPT_ANSWER_DISLIKE_REASONS'
    SCRIPT_ANSWER_DISLIKE_REASONS_DEFAULT = (
        '答非所问',
        '答案不正确',
    )
    # 答案满意度不满意原因收集后话术
    SCRIPT_ANSWER_DISLIKE_REASON_COLLECTED = 'SCRIPT_ANSWER_DISLIKE_REASON_COLLECTED'
    SCRIPT_ANSWER_DISLIKE_REASON_COLLECTED_DEFAULT = '呜呜，我会知错就改的，期待我的改变哦'

    # 会话满意度邀评话术
    SCRIPT_CONVERSATION_SATISFACTION_INVITE = 'SCRIPT_CONVERSATION_SATISFACTION_INVITE'
    SCRIPT_CONVERSATION_SATISFACTION_INVITE_DEFAULT = '给我的服务打个分哦'
    # 会话不满意原因
    SCRIPT_CONVERSATION_DISSATISFIED_REASONS = 'SCRIPT_CONVERSATION_DISSATISFIED_REASONS'
    SCRIPT_CONVERSATION_DISSATISFIED_REASONS_DEFAULT = (
        '未解决问题',
        '答案不合理'
    )
    # 会话满意度评价其他原因收集邀请话术
    SCRIPT_CONVERSATION_DISSATISFIED_OTHER_REASON_GUIDING = 'SCRIPT_CONVERSATION_DISSATISFIED_OTHER_REASON_GUIDING'
    SCRIPT_CONVERSATION_DISSATISFIED_OTHER_REASON_GUIDING_DEFAULT = '还有其他想对我说的吗?'
    # 会话满意度评价后话术
    SCRIPT_CONVERSATION_SATISFACTION_COMMITTED = 'SCRIPT_CONVERSATION_SATISFACTION_COMMITTED'
    SCRIPT_CONVERSATION_SATISFACTION_COMMITTED_DEFAULT = '谢谢你的使用，我会加倍努力，提供更好的服务哦'

    # 访客下线提示语
    SCRIPT_OFFLINE_NOTIFICATION = 'SCRIPT_OFFLINE_NOTIFICATION'
    SCRIPT_OFFLINE_NOTIFICATION_DEFAULT = '我已经下线了，感谢您的陪伴，如需继续咨询，请重新发送问题'

    """
    Configurations For Robot
    """

    # 机器人语言
    BOT_LANGUAGE = 'BOT_LANGUAGE'
    # 机器人默认语言
    BOT_LANGUAGE_DEFAULT = 'zh-Hans'

    # 机器人问答直接回复阈值
    BOT_DIRECTLY_REPLY_THRESHOLD = 'BOT_DIRECTLY_REPLY_THRESHOLD'
    # 机器人问答直接回复默认阈值
    BOT_DIRECTLY_REPLY_THRESHOLD_DEFAULT = 0.90

    # 机器人问答未知回复阈值
    BOT_UNKNOWN_REPLY_THRESHOLD = 'BOT_UNKNOWN_REPLY_THRESHOLD'
    # 机器人问答未知回复默认阈值
    BOT_UNKNOWN_REPLY_THRESHOLD_DEFAULT = 0.60

    # 网页聊天窗中COOKIE的KEY
    BOT_COOKIE_VISITOR_ID = 'visitorid'
    # 聊天窗中SESSION的KEY
    BOT_SESSION_ID = 'sessionid'

    # 网页聊天中访客默认头像
    BOT_VISITOR_AVATAR = 'static/img/00.jpg'
    # 机器人默认头像
    BOT_ROBOT_AVATAR = 'static/img/00.jpg'
    # 机器人默认昵称
    BOT_ROBOT_NAME = '小智'

    # 访客超时下线时间，默认300s
    BOT_OFFLINE_TIMEOUT = 'BOT_OFFLINE_TIMEOUT'
    BOT_OFFLINE_TIMEOUT_DEFAULT = 300

    # 是否启用答案满意度评价
    BOT_ENABLE_ANSWER_SATISFACTION = 'BOT_ENABLE_ANSWER_SATISFACTION'
    BOT_ENABLE_ANSWER_SATISFACTION_DEFAULT = True

    # 是否启用会话满意度评价
    BOT_ENABLE_CONVERSATION_SATISFACTION = 'BOT_ENABLE_ANSWER_SATISFACTION'
    BOT_ENABLE_CONVERSATION_SATISFACTION_DEFAULT = True

    SEG_SEPARATOR = '#'

    class ConstError(TypeError):
        pass

    class ConstCaseError(ConstError):
        pass

    def __setattr__(self, key, value):
        print()
        if key in self.__dict__.keys():
            # 存在性验证
            raise self.ConstError("Can't change a self variable: '%s'" % key)

        if not key.isupper():
            # 语法规范验证
            raise self.ConstCaseError("self variable must be combined with upper letters:'%s'" % key)

        __dict__[key] = value
